package com.exception.solve;

public class TestMyException {
    public static void main(String[] args) throws IllegalAgeEXception {
        Person p = new Person();
        p.setName("wyw");
        p.setAge(-100);
        System.out.println(p);
    }
}

class Person {
    private String name;
    private int age;

    public void setName(String name){
        this.name = name;
    }

    public void setAge(int age)throws IllegalAgeEXception{
        if (age<0){
            throw new IllegalAgeEXception("人的年龄不应该为负数");
        }
        this.age = age;
    }

    public String toString(){
        return "name is"+name+"and age is"+age;
    }
}